/**
 *梦迷.宫    
 * 进游戏步骤：1、主类添加到舞台。2、获取用户信息。3、生成各层容器。4、加载各配置文件。5、获取并初始化任务。
 * 6、生成框架UI、挂件模块入口图标。7、初始化新手引导。8、获取家园信息并加载生成花园。9、弹出登录奖励以及邀请好友面板。
 */ 
package com.zqgame.fantasyDream
{
//	import com.abram.utils.FPSCounter;
	import com.abram.utils.HashMap;
	import com.abram.utils.ShareObjectUtils;
	import com.adobe.serialization.json.JSON;
	import com.notice.NoticeCC;
	import com.notice.NoticeCS;
	import com.notice.NoticeSC;
	import com.proxy.Proxy;
	import com.zqgame.analysis.client.Send;
	import com.zqgame.fantasyDream.activity.GardenActivity;
	import com.zqgame.fantasyDream.bag.Bag;
	import com.zqgame.fantasyDream.cardMap.CardMap;
	import com.zqgame.fantasyDream.collection.BackgroundUtils;
	import com.zqgame.fantasyDream.collection.FriendCollectionPanel;
	import com.zqgame.fantasyDream.collection.MyCollectionPanel;
	import com.zqgame.fantasyDream.cons.Action;
	import com.zqgame.fantasyDream.cons.GoodsSubType;
	import com.zqgame.fantasyDream.cons.GoodsType;
	import com.zqgame.fantasyDream.data.ActivityObject;
	import com.zqgame.fantasyDream.data.AwardObject;
	import com.zqgame.fantasyDream.data.CardObject;
	import com.zqgame.fantasyDream.data.ConstData;
	import com.zqgame.fantasyDream.data.DataCache;
	import com.zqgame.fantasyDream.data.Distributer;
	import com.zqgame.fantasyDream.data.FriendObject;
	import com.zqgame.fantasyDream.data.GardenConst;
	import com.zqgame.fantasyDream.data.GoodsObject;
	import com.zqgame.fantasyDream.data.HouseInfoObject;
	import com.zqgame.fantasyDream.data.Model;
	import com.zqgame.fantasyDream.data.Page;
	import com.zqgame.fantasyDream.data.ToolsObject;
	import com.zqgame.fantasyDream.data.UserInfoObject;
	import com.zqgame.fantasyDream.effect.Cursor;
	import com.zqgame.fantasyDream.effect.DiyLoading;
	import com.zqgame.fantasyDream.effect.EffectManager;
	import com.zqgame.fantasyDream.effect.GainEffect;
	import com.zqgame.fantasyDream.effect.sound.SoundManager;
	import com.zqgame.fantasyDream.effect.sound.SoundNameMap;
	import com.zqgame.fantasyDream.garden.GardenInfoPanel;
	import com.zqgame.fantasyDream.garden.GardenView;
	import com.zqgame.fantasyDream.garden.item.Human;
	import com.zqgame.fantasyDream.help.Help;
	import com.zqgame.fantasyDream.noticeType.ConstCC;
	import com.zqgame.fantasyDream.noticeType.ConstCS;
	import com.zqgame.fantasyDream.noticeType.ConstSC;
	import com.zqgame.fantasyDream.panel.ContentFrame;
	import com.zqgame.fantasyDream.panel.EnergyCounterView;
	import com.zqgame.fantasyDream.panel.FreeGiftPanel;
	import com.zqgame.fantasyDream.panel.FrontFilm;
	import com.zqgame.fantasyDream.panel.FullScreenView;
	import com.zqgame.fantasyDream.panel.MsgBox;
	import com.zqgame.fantasyDream.panel.OneKeyOparePanel;
	import com.zqgame.fantasyDream.panel.OnlineAward;
	import com.zqgame.fantasyDream.panel.PopupManager;
	import com.zqgame.fantasyDream.panel.UserInfoView;
	import com.zqgame.fantasyDream.panel.bottom.BottmBarView;
	import com.zqgame.fantasyDream.puzzle.Puzzle;
	import com.zqgame.fantasyDream.race.Race;
	import com.zqgame.fantasyDream.race.RaceModel;
	import com.zqgame.fantasyDream.race.view.NoticeTxt;
	import com.zqgame.fantasyDream.race.view.RacePanel;
	import com.zqgame.fantasyDream.shop.Shop;
	import com.zqgame.fantasyDream.shop.view.ShopPanel;
	import com.zqgame.fantasyDream.subComponents.JsInterface;
	import com.zqgame.fantasyDream.subComponents.Res;
	import com.zqgame.fantasyDream.task.DailyTaskPanel;
	import com.zqgame.fantasyDream.task.DialogPanel;
	import com.zqgame.fantasyDream.task.TaskManager;
	import com.zqgame.fantasyDream.utils.GoodsUtils;
	import com.zqgame.fantasyDream.utils.UIUtils;
	
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageDisplayState;
	import flash.display.StageScaleMode;
	import flash.errors.IOError;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;
	import flash.external.ExternalInterface;
	import flash.filters.GlowFilter;
	import flash.geom.Rectangle;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	import flash.system.Security;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.utils.Timer;
	import flash.utils.setTimeout;
	
	import ghostcat.util.data.Hash;
	
	import utils.core.ContexMenuManager;
	
	import components.CarvelBG;
	import components.ScrollMsg;
	import components.TweenMsg;
	import components.TweenText;
	import components.toolTip.ToolTip;
	
	import org.caurina.transitions.Tweener;
	
	import resLib.UI;
	import resLib.version.VersionManager;
	
	//	import com.zqgame.fantasyDream.race.view.NoticeTxt;
	
	[SWF(width="750",height="650")]
	public class Dream extends Sprite
	{
		private var iniWidth:int = 750;
		private var iniHeight:int = 650;
		private var _backgroundLayer:Sprite;//背景层f
		private var _userInfoLayer:Sprite; //玩家属性层
		private var _houseLayer:Sprite; 	//房间层
		//		private var _onLineAwardLayer:Sprite; 	//在线奖励层
		private var _pendantLayer:Sprite;		//挂件层
		private var _collectionLayer:Sprite; //百宝盒层
		private var _friendCollectionLayer:Sprite; //百宝盒层
		
		private var _cardLayer:Sprite;	 	//关卡层 
		private var _bagLayer:Sprite; 		//背包层
		private var _buttonLayer:Sprite; 	//按钮层
		private var _puzzleLayer:Sprite;	//解密层
		private var _uiLayer:Sprite;		//UI 层
		private var _raceLayer:Sprite;    //比赛层
		
		private var _popupLayer:Sprite;	//弹出层
		private var _tipsLayer:Sprite;		//tips层
		private var _helpLayer:Sprite;		//新手引导层
		private var _effectLayer:Sprite;	//特效层
		private var _lockMask:Sprite;		//锁定游戏UI的遮挡层
		private var _requestLockMask:Sprite;		//向服务器请求时锁定游戏UI的遮挡层
		private var _maskSprite:Sprite;
		private var _gardenActivity:GardenActivity;
		
		private var _gainEffect:GainEffect;//获得各种收益、升级等特效动画
		private var _house:GardenView;			//花园对象
		private var _puzzle:Puzzle;		//解谜对象
		private var _serverErrorPanel:MovieClip;
		private var _simpleLoadingMc:MovieClip;//小loading动画
		private var _puzzleLoadingMc:MovieClip;//关卡loading动画
		private var _diyLoadingMc:MovieClip;//diyloading动画
		private var _gardenLoadingMc:MovieClip;
		private var _scrollMsg:ScrollMsg;//滚动信息
		private var _engeryEffectMc:MovieClip;
		private var userInfoView:UserInfoView;
		private var _goVipPageMc:MovieClip;
		private var _cardMapMc:CardMap;
		private var _shopMc:Shop;
		private var _friendCollectionPanel:FriendCollectionPanel;
		private var _myCollectionPanel:MyCollectionPanel;
		private var _gameBg:CarvelBG;
		private var _contentFrame:ContentFrame;
		private var _dailyTastBtn:SimpleButton;
		
		private var dailyPanel:DailyTaskPanel;
		private var _gardenInfo:GardenInfoPanel;
		
		
		//		private var _ChristmasMc:MovieClip;
		public function Dream()
		{
			super();
			flash.system.Security.allowDomain("*");
			
			this.addEventListener(Event.ADDED_TO_STAGE, addedToStage);			
		}
		
		private function addedToStage(evt:Event):void
		{
			this.removeEventListener(Event.ADDED_TO_STAGE, addedToStage);
			stage.align = StageAlign.TOP_LEFT//.TOP;
			stage.scaleMode = StageScaleMode.NO_SCALE; 
			stage.frameRate =24;
			stage.stageFocusRect = false;
			stage.addEventListener(Event.RESIZE, stageResize);
			DataCache.instance.iniWidth = stage.stageWidth;
			DataCache.instance.iniHeight = stage.stageHeight;
			TweenMsg.ini(stage);
			_simpleLoadingMc = UI.getUI("SimpleLoadingMc") as MovieClip;
			_simpleLoadingMc.stop();
			ASDebugger.debug("main.swf所在页面地址："+stage.loaderInfo.url);
			if(VersionManager.debugMode)//内网
			{
				Proxy.serverURL = VersionManager.versionFileData.debugServerURL; 
			}
			else//外网
			{
				var loaderURL:String = stage.loaderInfo.url;
				Proxy.serverURL = loaderURL.substring(0, loaderURL.indexOf(".com",7)+4)+"/";
			}
			if(int(stage.loaderInfo.parameters["flag"]) == 1)//第一次进游戏
			{
				DataCache.instance.isNewUser = true;
			}
			else
			{
				DataCache.instance.isNewUser = false;
			}
			Res.ini(Object(parent.parent).prePath);
			var advanceConfig:Object = Object(parent.parent).advanceConfig;
			DataCache.instance.innerTest=advanceConfig.innerTest;
			var userId:*=stage.loaderInfo.parameters["account"];
			if(userId==undefined)
				userId = advanceConfig.testUserId;//
			
			Proxy.sessionId = stage.loaderInfo.parameters["sessionId"];
			Proxy.userId = String(userId);
			Proxy.debugMode = VersionManager.debugMode;
			enterGame();
		}
		
		
		
		private function enterGame(data:Object=null):void
		{
			//数据分析记录 
			Send.login(Proxy.userId);
			
			DataCache.instance.diamondDouble = stage.loaderInfo.parameters["diamondDouble"];
//			ASDebugger.debug("sessionid:"+Proxy.sessionId);
			if(! VersionManager.debugMode)
			{
				if((Proxy.sessionId == null) || (Proxy.sessionId=="") || (Proxy.sessionId == "undefined"))
				{
					flash.utils.setTimeout(refresh,1000);
					showTweenMsg("获取sessionId失败，1秒后重新尝试登录。");
					return;
				}
			}
			NoticeSC.addListener(NoticeSC.DATABASE_DOWN, onDataBaseDown);
			NoticeSC.addListener(NoticeSC.SERVER_CLOSE, onServerClose);
			NoticeSC.addListener(NoticeSC.SERVER_ERROR, onServerError);
			NoticeSC.addListener(NoticeSC.SESSION_EXPIRE, onSessionExpire);
			
			Distributer.listen(); //开始侦听S到C的需要分发消息的消息
			JsInterface.ini();
			Shop.instance().ini();
			ToolTip.ini(stage, UI.getMovieClip('panel.TipsSkin'), new Rectangle(40,20,30,70), 150, 58);
			DataCache.instance.testMode = false;	//开启测试模式
			DataCache.instance.userInfo.id = Proxy.userId;
			Cursor.ini([UI.getUI("cursor.Normal"), 
				UI.getUI("cursor.DragIcon"),
				UI.getUI("skin.cursor.MoveSkin"),
				UI.getUI("skin.cursor.ChangeDirectionSkin"),
				//UI.getUI("skin.cursor.ChangeDirectionSkin"),
				UI.getUI("skin.cursor.SellSkin"),
				UI.getUI("skin.cursor.RecoverSkin"),
				UI.getUI("skin.cursor.SendGiftSkin")
			], stage, false);
			_backgroundLayer = new Sprite();
			_backgroundLayer.mouseChildren = false;
			_backgroundLayer.mouseEnabled = false;
			_userInfoLayer 	= new Sprite();
			_houseLayer 	= new Sprite();
			_collectionLayer 	= new Sprite();
			_friendCollectionLayer = new Sprite();
			_cardLayer		= new Sprite();
			_raceLayer      = new Sprite();
			_bagLayer 		= new Sprite();
			_buttonLayer 	= new Sprite();
			_puzzleLayer	= new Sprite();
			_uiLayer		= new Sprite();
			_pendantLayer		= new Sprite();
			_pendantLayer.mouseEnabled = false;
			_lockMask 		= new Sprite();
			_requestLockMask= new Sprite();
			_effectLayer	= new Sprite();
			_tipsLayer		= new Sprite();
			_helpLayer		= new Sprite();
			_helpLayer.mouseEnabled = false;
			_popupLayer 	= new Sprite();
			_maskSprite = new Sprite();
			
			_userInfoLayer.mouseEnabled = false;
			_houseLayer.y = 0;
			_cardLayer.y = 0;
			_bagLayer.y = 510;
			_bagLayer.mouseEnabled = false;
			_buttonLayer.y = 515;
//			_buttonLayer.x = 5; 
			_buttonLayer.mouseEnabled = false;
			_simpleLoadingMc.x = (stage.stageWidth - _simpleLoadingMc.width)*0.5;
			_simpleLoadingMc.y = (stage.stageHeight - _simpleLoadingMc.height)*0.5;
			
			_scrollMsg = new ScrollMsg((stage.stageWidth - 140), 20, 2);
			_pendantLayer.addChild(_scrollMsg);
			
			_gameBg = new CarvelBG((UI.getUI("GameBg") as BitmapData), stage.stageWidth, stage.stageHeight, CarvelBG.autoScale_full);
			stage.addChildAt(_gameBg, 0);
			this.addChild(_houseLayer);
			
			this.addChild(_pendantLayer);
			
			
			this.addChild(_collectionLayer);
			this.addChild(_bagLayer);
			
			this.addChild(_raceLayer);                                            
			this.addChild(_buttonLayer);
			
			this.addChild(_puzzleLayer);
			
			this.addChild(_uiLayer);
			this.addChild(_userInfoLayer);
			this.addChild(_cardLayer);
			this.addChild(_backgroundLayer);
			this.addChild(_popupLayer);
			this.addChild(_effectLayer);
			this.addChild(_friendCollectionLayer);
			this.addChild(_tipsLayer);
			this.addChild(_helpLayer);
			
			stage.addChild(_maskSprite);
			
			
			//Tick.instance;
			
			NoticeCC.addListener(ConstCC.MSG_SHOW,showMsg);
			NoticeCC.addListener(ConstCC.SHOW_TWEEN_MSG,showTweenMsg);
			NoticeCC.addListener(ConstCC.ADDD_SCROLL_NOTICE, addScrollNotice);
			//NoticeCC.addListener(ConstCC.PAGE_TO_House,showHouse);
			NoticeCC.addListener(ConstCC.PATE_TO_GARDEN,showGarden);
			NoticeCC.addListener(ConstCC.PAGE_TO_CARD,showCard);
			NoticeCC.addListener(ConstCC.SHOW_SHOP,showShop);
			NoticeCC.addListener(ConstCC.PAGE_TO_RACE,showRace);
			NoticeCC.addListener(ConstCC.PAGE_TO_COLLECTION,openCollectionPanel);
			NoticeCC.addListener(ConstCC.PAGE_TO_FRIEND_COLLECTION,openFriendCollectionPanel);
			NoticeCC.addListener(ConstCC.CARD_HIDDEN,hiddenCard);
			NoticeCC.addListener(ConstCC.PAGE_TO_PUZZLE,showPuzzle);
			NoticeCC.addListener(ConstCC.UN_REQUEST_LOCK,unRequestLock);
			NoticeCC.addListener(ConstCC.REQUEST_LOCK,requestLock);
			NoticeCC.addListener(ConstCC.UNLOCK_GAME,unLockGame);
			NoticeCC.addListener(ConstCC.LOCK_GAME,lockGame);
			NoticeCC.addListener(ConstCC.SHOW_LOADING,showLoading);
			NoticeCC.addListener(ConstCC.REMOVE_LOADING,removeLoading);
			//			NoticeCC.addListener(ConstCC.UNLOCK_BOTTOMBAR,unlockBottomBar);
			//			NoticeCC.addListener(ConstCC.LOCK_BOTTOMBAR,lockBottomBar);
			NoticeCC.addListener(ConstCC.PUZZLE_LOADING_SHOW,showPuzzleLoading);
			NoticeCC.addListener(ConstCC.PUZZLE_LOADING_HIDDEN,hiddenPuzzleLoading);
			
			NoticeCC.addListener(ConstCC.SHOW_GARDEN_LOADING,showGardenLoading);
			NoticeCC.addListener(ConstCC.HIDDEN_GARDEN_LOADING,hiddenGardenLoading);
			
//			NoticeCC.addListener(ConstCC.PUZZLE_LOADING_SHOW,showHouseLoading);
//			NoticeCC.addListener(ConstCC.PUZZLE_LOADING_HIDDEN,hiddenHouseLoading);
			
			NoticeCC.addListener(ConstCC.HIDDEN_GARDEN,hiddenHouse);
			NoticeCC.addListener(ConstCC.SHOW_PANDENT,showPendant);
			NoticeCC.addListener(ConstCC.HIDDEN_PANDENT,hiddenPendant);
			NoticeCC.addListener(ConstCC.SHOWDIYHOUSE_LOADING,showHouseLoading);
			NoticeCC.addListener(ConstCC.HIDEHOUSE_LOADING,hiddenHouseLoading);
			NoticeCC.addListener(ConstCC.SHOW_FRONTFILM,showfrontfilm);
			NoticeCC.addListener(ConstCC.SCREEN_SHAKE, screenShake);
			
			NoticeCC.addListener(ConstCC.FULL_SCREEN_NOTICE,screenCtr);
			this.stage.addEventListener(KeyboardEvent.KEY_DOWN,mouseKeyHanlde);
			this.stage.addEventListener(MouseEvent.CLICK,clickHandler);
			Model.instance.loadUserInfo(onLoadUserInfo);
			
		}
		
		private function clickHandler(evt:MouseEvent):void
		{
			trace(evt.target);
		}
		
		
		private function mouseKeyHanlde(evt:KeyboardEvent):void
		{
			switch(evt.keyCode)
			{
				case 27:
//					if(DataCache.instance.stage.displayState==StageDisplayState.FULL_SCREEN)
//					{
						DataCache.instance.stage.displayState=StageDisplayState.NORMAL;
						DataCache.instance.fullScreenStatus=false;
						NoticeCC.dispatch(ConstCC.FULL_SCREEN_NOTICE);
//					}
					break;
			}
		}
		
		private function screenCtr(data:*):void
		{
			//t 
		}
		
		private function onLoadLoudSpeakerHandler(data:Object = null):void
		{
			if(data.returnCode == 1)
			{
				var topNoticeTxtformat:TextFormat= new TextFormat();
				topNoticeTxtformat.font = "黑体";
				topNoticeTxtformat.size = 14;
				topNoticeTxtformat.align = "center"; 
				topNoticeTxtformat.color = 0xffff00;
				if(data.list.length>=1)
				{
					var reString:String
					if(data.list[0].recieveName == "trade")
					    reString = "经过"+data.list[0].sendName+"的不懈努力，成功兑换到了"+data.list[0].content+"！";
					else
						reString = data.list[0].sendName +"对"+data.list[0].recieveName+"说："+data.list[0].content;
					var noticeTxt:NoticeTxt = new NoticeTxt(reString, 0, topNoticeTxtformat, null, false);
					NoticeCC.dispatch(ConstCC.ADDD_SCROLL_NOTICE, noticeTxt);
					flash.utils.setTimeout(dispatchNoticeTxt,5*60*1000);
				}
				
			}
			function dispatchNoticeTxt():void
			{
				NoticeCS.request(ConstCS.NEW_DELLOUDSPEAKERMSG, {msgId:data.list[0].id}, onDelLoudSpeakerHandler);
			}
			function onDelLoudSpeakerHandler(adata:Object = null):void
			{
				if(adata.returnCode == 1)
				{
					data.list.shift();
					if(data.list.length>=1)
					{
						if(data.list[0].recieveName == "trade")
							reString = "经过"+data.list[0].sendName+"的不懈努力，成功兑换到了"+data.list[0].content+"！";
						else
							reString = data.list[0].sendName +"对"+data.list[0].recieveName+"说："+data.list[0].content;
						NoticeCC.dispatch(ConstCC.ADDD_SCROLL_NOTICE, noticeTxt);
						flash.utils.setTimeout(dispatchNoticeTxt,5*60*1000);
					}
				}
			}
		}
		
		private function addPendentObj(data:Object = null):void
		{//return;//g 
			_pendantLayer.addChild(OnlineAward.getDefault());
			OnlineAward.getDefault().x = 695;
			OnlineAward.getDefault().y = 105;
			
			
		}
		
		private function screenShake(data:Object):void
		{
			var lastX:int = this.x;
			var lastY:int = this.y;
			this.x = -20;
			this.y = 20;
			Tweener.addTween(this, {x:lastX, time:0.4, transition:"easeOutElastic"});
			Tweener.addTween(this, {y:lastY, time:0.4, transition:"easeOutElastic"});
			
		}
		
		private function goVip(evt:MouseEvent = null):void
		{
			JsInterface.openCommonVip();
		}
		
		
		//显示片头
		private function showfrontfilm(data:Object=null):void
		{
			NoticeCC.removeListener(ConstCC.SHOW_FRONTFILM,showfrontfilm);
			_houseLayer.addChildAt(new FrontFilm(),0);
			this.lockGame(0);
		}
		
		//玩家信息加载完成
		private function onLoadUserInfo():void
		{
			this.setEnabled(false);
			
			BackgroundUtils.loadData();
			
			DataCache.instance.uiLayer = _uiLayer;
			DataCache.instance.pendantLayer = _pendantLayer;
			
			DataCache.instance.stage = this.stage;
			DataCache.instance.tipsLayer = _tipsLayer;
			DataCache.instance.popupLayer = _popupLayer;
			DataCache.instance.puzzleLayer = _puzzleLayer;
			//			DataCache.instance.taskLayer=_taskLayer;
			
//			var background:MovieClip = MovieClip(UI.getUI('skin.MainBorder'));
//			background.mouseChildren=false;
//			background.mouseEnabled=false;
//			background.cacheAsBitmap=true;
//			_backgroundLayer.addChild(background);
			PopupManager.instance.ini(_popupLayer, this.stage);
			EffectManager.instance.container=_effectLayer;
			Help.getDefault().ini(stage, _helpLayer);
			DialogPanel.getDefault().ini(stage);
			TaskManager.getDefault().displayObj.addEventListener("taskReady",onTaskReady);
			
			_pendantLayer.addChild(TaskManager.getDefault().displayObj);//g 
//			OneKeyOparePanel.getDefault().x= 685;
//			OneKeyOparePanel.getDefault().y = 300;
//			_pendantLayer.addChild(OneKeyOparePanel.getDefault());
			
			if(dailyPanel == null)
				dailyPanel = DailyTaskPanel.getDefault();
			_dailyTastBtn = UI.getUI("dailyTaskIcon","popPanelUI") as SimpleButton;
			_dailyTastBtn.addEventListener(MouseEvent.CLICK,openDailyTask);
			_dailyTastBtn.x = TaskManager.getDefault().displayObj.x+5;
			_dailyTastBtn.y = TaskManager.getDefault().displayObj.y+320;
			_pendantLayer.addChild(_dailyTastBtn);
			
			//初始化碎片模块
			_myCollectionPanel = MyCollectionPanel.instance();
			
			//加载活动的配置文件
			NoticeCS.request(ConstCS.NEW_CONFIG, {name:"activity"}, onLoadActivityConfigCompleteHandler, false, true);
			//加载关卡配置文件
			NoticeCS.request(ConstCS.NEW_CONFIG, {name:"card"}, onLoadCardConfigCompleteHandler, false, true);
			//加载抽奖配置文件
			NoticeCS.request(ConstCS.NEW_CONFIG, {name:"award"}, onLoadawardConfigCompleteHandler, false, true);
			//加载道具物品配置
			NoticeCS.request(ConstCS.NEW_CONFIG, {name:"tools"}, onLoadToolsConfigCompleteHandler, false, true);
			
			Res.load("res/config/uiOpenCtr.txt", "uiOpenCtr", "", loadUiOpenCtrComplete, loadUiOpenCtrError,null,5);
		}
		
		
		private function loadUiOpenCtrComplete(cont:String):void
		{
			ConstData.uiOpenCtrData = JSON.decode(cont);
			//加载家园物品配置
			NoticeCS.request(ConstCS.NEW_CONFIG, {name:"goods"}, onLoadGoodsConfigCompleteHandler, false, true);
		}
		
		private function loadUiOpenCtrError():void
		{
			trace("-------------加载等级控制文件出错---------");
			//加载家园物品配置
			NoticeCS.request(ConstCS.NEW_CONFIG, {name:"goods"}, onLoadGoodsConfigCompleteHandler, false, true);
		}
		
		/**
		 * 加载物品配置文件处理器，加载完成后交给GoodsUtils处理
		 * @param	evt
		 */
		private function onLoadGoodsConfigCompleteHandler(content:Object):void
		{
			Res.load("res/config/itemList.txt", "itemList", "", onPuzzleObjConfigLoad);
			GoodsUtils.update(content);
			init();
		}
		
		private function openDailyTask(evt:MouseEvent):void
		{
			
			PopupManager.addPopUp(dailyPanel,true,true,true);
//			var dis:FreeGiftPanel = new FreeGiftPanel(new Object());
//			PopupManager.addPopUp(dis,true,true,true);
		}
		
		private function init():void
		{
			_gainEffect = new GainEffect(stage);
			userInfoView = new UserInfoView(_userInfoLayer);
			
			_gardenInfo = GardenInfoPanel.instance;
			_gardenInfo.y=48;
			_gardenInfo.x=(stage.stageWidth-260)*0.5;
			_userInfoLayer.addChild(_gardenInfo);
			
//			_bottomPanel = new BottomPanel(_buttonLayer);
			var bottomBar:BottmBarView=new BottmBarView(_buttonLayer);
			DataCache.instance.userInfoView = userInfoView;
			//bottomHeight=250;
			
//			var bottonBarView:BottmBarView = new BottmBarView(_bagLayer);
			//var fullScreenView:FullScreenView = new FullScreenView(this);	//全屏模块	
//			var toolsBarView:ToolsBarView = new ToolsBarView(_buttonLayer); //工具条
			DataCache.instance['buy_diamond_url'] = '#'; //购买宝石的url
			
			Model.instance.loadFriendList();	//加载好友列表
			//Model.instance.loadHouseInfo();	//加载房间信息
			//Model.instance.loadShopGoods();	//加载商店物品
			//Model.instance.loadBagData();		//加载背包数据
			NoticeCC.dispatch(ConstCC.PATE_TO_GARDEN,DataCache.instance.userInfo.id);
			addPendentObj();
			Race.getDefault().quereyRace();
			NoticeCS.request(ConstCS.NEW_LOUDSPEAKERMSG, null, onLoadLoudSpeakerHandler);
			
		}
		
		//任务准备完毕
		private function onTaskReady(evt:Event=null):void
		{
			TaskManager.getDefault().displayObj.removeEventListener("taskReady",onTaskReady);
			if(TaskManager.isFirstTaskOver())
				Proxy.firstTaskOver = true;
			else//第一个任务没完成
			{
				Proxy.firstTaskOver = false;
				
			}
			//NoticeCC.dispatch(ConstCC.INVITE_FRIEND);
			this.setEnabled(true);
			
		}
		
		private function setEnabled(value:Boolean=false):void
		{
			this.mouseChildren = value;
			this.mouseEnabled = value;
		}
		
		
		private function openCollectionPanel(data:Object=null):void
		{
//			if(_friendCollectionPanel !=null || _myCollectionPanel != null)
			if(DataCache.instance.collectionUIDownbool == true)
			{
				onCollectionUILoad();
			}
			else
			{
				UIUtils.loadModule("collectionUI",onCollectionUILoad);
			}
			function onCollectionUILoad(mc:MovieClip=null):void
			{
//				hiddenHouse();
				DataCache.instance.collectionUIDownbool = true;
				if(_myCollectionPanel == null)
				{
					_myCollectionPanel = MyCollectionPanel.instance();
					
				}
				
//				_collectionLayer.addChild(_myCollectionPanel);
//				_myCollectionPanel.x = (stage.stageWidth-_myCollectionPanel.width)*0.5;
//				_myCollectionPanel.y = (stage.stageHeight-_myCollectionPanel.height)*0.5;
//				_collectionLayer.visible = true;
				_myCollectionPanel.showUI();
				PopupManager.addPopUp(_myCollectionPanel,true,true,true);
			}
			
			
		}
		/*private function unlockBottomBar(data:Object=null):void{
		_buttonLayer.mouseChildren=true;
		_bagLayer.mouseChildren=true;
		}
		private function lockBottomBar(data:Object=null):void{
		_buttonLayer.mouseChildren=false;
		_bagLayer.mouseChildren=false;
		}*/
		private function openFriendCollectionPanel(data:Object=null):void
		{
//			var d:DisplayObject = _friendCollectionLayer.getChildByName("exchangeChips");
			if(_friendCollectionPanel !=null)
			{
				onCollectionUILoad();
			}
			else
			{
				UIUtils.loadModule("collectionUI",onCollectionUILoad);
			}
			function onCollectionUILoad(mc:MovieClip=null):void
			{
//				if(_friendCollectionPanel == null)
//				{
//					_friendCollectionPanel = new FriendCollectionPanel();
//					
//				}
				_friendCollectionPanel = new FriendCollectionPanel();
//				_friendCollectionLayer.addChild(_friendCollectionPanel);
				PopupManager.addPopUp(_friendCollectionPanel,true,true,true);

			}
		}
		
		private function showGarden(userId:String=null):void
		{
			Page.currentPage = Page.GARDEN;
			//return;//g 
			if(userId==null)
				userId=DataCache.instance.userInfo.id;
			if(_house == null)
			{ 
//				
				_house = new GardenView(userId);
				_houseLayer.addChild(_house);
				_house.addEventListener(Event.REMOVED_FROM_STAGE, leaveHouse);
				DataCache.instance.gardenView = _house; 
			}
			else
			{ 
				_houseLayer.addChild(_house);
				_house.changeGarden(userId);
			}
			if(_gardenActivity == null)
				_gardenActivity = new GardenActivity();
			var rec:Rectangle = new Rectangle(-_effectLayer.x, -_effectLayer.y, stage.stageWidth, stage.stageHeight)
			_gardenActivity.showGardenScreenMc(rec, _effectLayer);
			_gardenActivity.show();
			showPendant();
			var layerIndex:int = this.getChildIndex(_houseLayer)+1;
			if(_userInfoLayer.parent == null)
				this.addChildAt(_userInfoLayer,layerIndex);
			if(_buttonLayer.parent == null)
				this.addChildAt(_buttonLayer,layerIndex);
			if(_contentFrame && _contentFrame.parent)
			{
				_contentFrame.parent.removeChild(_contentFrame);
			}
			NoticeCC.dispatch(ConstCC.TOOL_BUTTON_CLASS, "myHouseToolsBar");
			if(userId == DataCache.instance.userInfo.id)//每次进入自己家园，查询各属性
			{
				NoticeCS.request(Action.USER_INFO);
			}
		}
		
		//离开花园页
		private function leaveHouse(evt:Event):void
		{
			this.removeChild(_userInfoLayer);
			this.removeChild(_buttonLayer);
			
//			if(stage.stageWidth>ConstData.NormalWidth || stage.stageHeight>ConstData.NormalHeight)//全屏
//			{
				if(_contentFrame == null)
				{
					_contentFrame = new ContentFrame();
				}
				_contentFrame.x = int((stage.stageWidth-_contentFrame.width)*0.5);
				_contentFrame.y = int((stage.stageHeight-_contentFrame.height)*0.5);
				stage.addChildAt(_contentFrame, 1);
//			}
			
		}
		
		//跳到关卡页面
		private function showCard(data:Object):void
		{
			if(_cardMapMc ==null)
			{
				UIUtils.loadModule("CardMapModelUI",onCardMapModelLoad);
			}
			else
			{
				onCardMapModelLoad();
			}
			function onCardMapModelLoad(mc:MovieClip=null):void
			{
				Page.currentPage = Page.CARD;
				hiddenHouse();
				if(_cardMapMc ==null)
				{
					_cardMapMc = CardMap.getDefault();
				}
				_cardLayer.addChild(_cardMapMc);
				NoticeCC.dispatch(ConstCC.TOOL_BUTTON_CLASS, "checkpoint");
			}
		}
		
		//跳到商城页面 
		private function showShop(data:Object=null):void
		{
			Page.currentPage = Page.SHOP;
			if(_shopMc == null) 
			{
				UIUtils.loadModule("shopUI",onShopUILoad);
			}	
			else
			{
				onShopUILoad();
			}
			function onShopUILoad(mc:MovieClip=null):void
			{
				hiddenHouse();
				if(_shopMc == null)
				{
					_shopMc = Shop.instance();
				}
				if(data)
					_shopMc.openShop(!data.tag?0:data.tag,data.currency?data.currency:-1);
				else
					_shopMc.openShop();
				
				_cardLayer.addChild(_shopMc);
			}
		}
		
		//跳到解谜页面
		private function showRace(data:Object):void
		{
//			NoticeCC.dispatch(ConstCC.SHOW_TWEEN_MSG,"竞技场暂未开放,敬请期待！");
//			return;
			Page.currentPage = Page.RACE;
			_gardenActivity.hidden();
			hiddenHouse();
			_raceLayer.addChild(Race.getDefault());
			NoticeCC.dispatch(ConstCC.TOOL_BUTTON_CLASS, "checkpoint");
		}
		
		private function hiddenHouse(data:Object=null):void
		{
			_gardenActivity.hidden();
			hiddenPendant();
			if(_house && _houseLayer.contains(_house))
			{	
				_houseLayer.removeChild(_house);
				//_house.destory();
			}
		}
		
		//隐藏挂件
		private function hiddenPendant(data:Object=null):void
		{
			if(_pendantLayer.parent)
				_pendantLayer.parent.removeChild(_pendantLayer);
		}
		
		//将挂件层显示在家园层之上
		private function showPendant(data:Object=null):void
		{
			if(_pendantLayer.parent == null)
			{
				var index:int = this.getChildIndex(_houseLayer);
				if(index>=0)
					this.addChildAt(_pendantLayer, index+1);
				else
					this.addChildAt(_pendantLayer, this.numChildren);
			}
			
		}
		
		private function hiddenCard(data:Object=null):void
		{
			if(_cardLayer.numChildren>0)
				_cardLayer.removeChildAt(0);
		}
		
		//跳到关卡解谜页面
		private function showPuzzle(data:Object):void
		{
			_gardenActivity.hidden();
			hiddenCard();
			hiddenHouse();
			if(_puzzleLoadingMc ==null)
			{
				UIUtils.loadModule("puzzleUI",onCardLoadingLoad)
			}
			else
			{
				onCardLoadingLoad();
			}
			SoundManager.playSound(SoundNameMap.openSence);
			function onCardLoadingLoad(mc:MovieClip=null):void
			{
				SoundManager.stopSound("m_0");
				ASDebugger.debug("开始生成解谜");
				if(_puzzle == null)
				{
					_puzzle = new Puzzle(stage);
					_puzzle.x = 1;
					_puzzle.y = -4;
				} 
				_puzzle.update(data);
				DataCache.instance.puzzlebool = true;
				_puzzleLayer.addChild(_puzzle);
			}
			
			
		}
		
		
		private function showMsg(data:Object):void
		{
			var msg:String = data.msg;
			var title:String = data.title;//可为空
			var onConfirmFun:Function = data.onConfirm;//可为空
			
			var msgBox:MsgBox = new MsgBox(msg, title, onConfirmFun);
			msgBox.show();
//			msgBox.x = (stage.stageWidth - msgBox.width)*0.5;
//			msgBox.y = (stage.stageHeight - msgBox.height)*0.5;
//			PopupManager.addPopUp(msgBox,true,true);
		}
		
		//显示舞台弹出文字信息
		private function showTweenMsg(msg:String):void
		{
			msg = msg?msg:"";
			var textfield:TextField = new TextField();
			textfield.autoSize = "left";
			textfield.height = 30;
			textfield.text = msg;
//			TweenMsg.addTween(textfield);
			TweenMsg.addRibbonTween(textfield);
		}
		
		//添加顶部跑马灯信息
		private function addScrollNotice(disObj:DisplayObject):void
		{
			if(!DataCache.instance.puzzlebool)
				_scrollMsg.addContent(disObj,3);
		}
		
		private function onPuzzleObjConfigLoad(cont:String):void
		{
			var puzzleObjConfig:* = JSON.decode(cont);
			var objType:String;
			var obj:Object;
			for(objType in puzzleObjConfig)
			{
				for each(obj in puzzleObjConfig[objType].items)
				{
					DataCache.instance.puzzleObjConfig.put(obj.id, {id:obj.id, name:obj.name, type:objType});
				}
			}
		}
		
		/**
		 * 处理抽奖配置文件，把数据保存在datacache 的awardMap里，根据
		 * @param	evt
		 */
		private function onLoadawardConfigCompleteHandler(jsonObj:Object):void
		{
			var reward:AwardObject = null;
			var awardMap1:HashMap = new HashMap();	
			var awardMap2:HashMap = new HashMap();	
			var awardMap3:HashMap = new HashMap();	
			for each(var item:Object in jsonObj)
			{
				
				reward = new AwardObject();
				reward.cardId = item.cardId;
				reward.minValue = item.minValue;
				reward.maxValue = item.maxValue;
				reward.type = item.type;
				if(item.type == 1)
				{
					awardMap1.put(item.cardId,reward);
				}
				if(item.type == 2)
				{
					awardMap2.put(item.cardId,reward);
				}
				if(item.type == 3)
				{
					awardMap3.put(item.cardId,reward);
				}
				
			}
			DataCache.instance.awardVector.push(awardMap1,awardMap2,awardMap3);
		}
		
		/**
		 * 处理道具配置文件，把数据保存在datacache 的ToolsMap里，根据
		 * @param	evt
		 */
		private function onLoadToolsConfigCompleteHandler(jsonObj:Object):void
		{
			var tool:ToolsObject = null;
			var ToolsMap:HashMap = new HashMap();	
			var ToolsMap1:HashMap = new HashMap();
			for each(var item:Object in jsonObj)
			{
				tool = new ToolsObject();
				tool.toolsId = item.id;
				tool.name =	item.name;
				tool.description = item.description;
				tool.openLevel = item.open_level;
				tool.subType = item.subType;
				tool.type = item.type;
				ToolsMap.put(item.toolsId,tool);
			}
			DataCache.instance.ToolsMap = ToolsMap;
		}
		
		
		/**
		 * 处理活动配置文件，把数据保存在datacache 的activityMap里，根据
		 * @param	evt
		 */
		private function onLoadActivityConfigCompleteHandler(jsonObj:Object):void
		{
			var activity:ActivityObject = null;
			for each(var item:Object in jsonObj)
			{
				activity = new ActivityObject();
				activity.id = item.id;
				activity.name = item.name;
				activity.content = item.content;
				activity.newest = item.newest;
				activity.url = item.url;
				activity.targetUrl = item.targetUrl;
				DataCache.instance.activityMap.put(item.id, activity);
			}
		}
		
		private function onLoadCardConfigCompleteHandler(jsonObj:Object):void
		{
			var cardObj:CardObject = null;
			for each (var item:Object in jsonObj)
			{
				cardObj = new CardObject();
				cardObj.abtainExp = item.abtain_exp;
				cardObj.abtainGold = item.abtain_gold;
				cardObj.energy = item.energy;
				cardObj.findNum = item.find_num;
				cardObj.gold = item.gold;
				cardObj.id = item.id;
				cardObj.honour = item.honour;
				cardObj.maxTime = item.max_time;
				cardObj.name = item.name;
				cardObj.newest = item.newest;
				cardObj.openStatus = CardObject.CLOSE;
				cardObj.proName = item.pro_name;
				cardObj.toolsPrecent = item.tools_precent;
				cardObj.currentDegree = 0;//默认当前难度是0，获得服务器端信息后改变改值
				DataCache.instance.cardMap.put(String(cardObj.id), cardObj);
			}
			
		}
		
		//向服务器请求时锁定游戏主界面
		private function requestLock(data:Object=null):void
		{
			if(stage)
			{
				if(_requestLockMask.width < stage.stageWidth)
				{
					_requestLockMask.graphics.beginFill(0x0,0.3);
					_requestLockMask.graphics.drawRect(0,0,stage.stageWidth, stage.stageHeight);
					_requestLockMask.graphics.endFill();
					if(_simpleLoadingMc)
					{
						stage.addChild(_simpleLoadingMc);
						_simpleLoadingMc.play();
					}
				}
			}
			else
			{
				if(_requestLockMask.width < this.width)
				{
					_requestLockMask.graphics.beginFill(0x0,0.3);
					_requestLockMask.graphics.drawRect(0,0,this.width, this.height);
					_requestLockMask.graphics.endFill();
				}
				if(_simpleLoadingMc)
				{
					this.addChild(_simpleLoadingMc);
					_simpleLoadingMc.play();
				}
			}
			
			this.addChildAt(_requestLockMask,getChildIndex(_popupLayer));
		}
		
		//取消请求锁定
		private function unRequestLock(data:Object=null):void
		{
			if(_requestLockMask && _requestLockMask.parent)
				_requestLockMask.parent.removeChild(_requestLockMask);
			if(_simpleLoadingMc)
			{
				if(_simpleLoadingMc.parent)
					_simpleLoadingMc.parent.removeChild(_simpleLoadingMc);
				_simpleLoadingMc.stop();
			}
		}
		
		//显示解谜loading
		private function showGardenLoading(data:Object):void
		{
			lockGame();
//			hiddenHouse();
			if(_gardenLoadingMc ==null)
			{
//				_diyLoadingMc = UI.getUI("modelLoading","commonUI") as MovieClip;
				_gardenLoadingMc = new DiyLoading();
				_gardenLoadingMc.mouseChildren = false;
				_gardenLoadingMc.mouseEnabled = false;
			}
//			_gardenLoadingMc.x=(stage.stageWidth-_gardenLoadingMc.width)*0.5;
//			_gardenLoadingMc.y =(stage.stageHeight - _gardenLoadingMc.height)*0.5;
			_gardenLoadingMc.x=0;
			_gardenLoadingMc.y = 0;
			 stage.addChild(_gardenLoadingMc);
		}
		
		
		
		//隐藏解谜loading
		private function hiddenGardenLoading(data:Object=null):void
		{
			if(_gardenLoadingMc && _gardenLoadingMc.parent)
				_gardenLoadingMc.parent.removeChild(_gardenLoadingMc);
			unLockGame();
		}
		
		
		//显示解谜loading
		private function showHouseLoading(data:Object):void
		{
			lockGame();
			//			hiddenHouse();
			if(_diyLoadingMc ==null)
			{
				_diyLoadingMc = UI.getUI("modelLoading","commonUI") as MovieClip;
				//				_diyLoadingMc = new DiyLoading();
				_diyLoadingMc.mouseChildren = false;
				_diyLoadingMc.mouseEnabled = false;
				
				
			}
			_diyLoadingMc.x=(stage.stageWidth-_diyLoadingMc.width)*0.5;
			_diyLoadingMc.y =(stage.stageHeight - _diyLoadingMc.height)*0.5;
			//			_diyLoadingMc.x=0;
			//			_diyLoadingMc.y = 0;
			stage.addChild(_diyLoadingMc);
		}
		
		
		
		//隐藏解谜loading
		private function hiddenHouseLoading(data:Object=null):void
		{
			if(_diyLoadingMc && stage.contains(_diyLoadingMc))
				stage.removeChild(_diyLoadingMc);
			unLockGame();
		}
		
		
		
		//锁定游戏主界面，不想被锁定的对象请添加到_popupLayer层以上的层次中
		private function lockGame(maskAlpha:Number=0.5):void
		{
			trace("");
			trace("加锁");
			if(stage)
			{
				if(_lockMask.width < stage.stageWidth)
				{
					_lockMask.graphics.beginFill(0x0,maskAlpha);
					_lockMask.graphics.drawRect(0,0,stage.stageWidth, stage.stageHeight);
					_lockMask.graphics.endFill();
				}
				else
				{
					_lockMask.alpha = maskAlpha;
				}
			}
			else
			{
				if(_lockMask.width < this.width)
				{
					_lockMask.graphics.beginFill(0x0,maskAlpha);
					_lockMask.graphics.drawRect(0,0,this.width, this.height);
					_lockMask.graphics.endFill();
				}
				else
				{
					_lockMask.alpha = maskAlpha;
				}
			}
			
			this.addChildAt(_lockMask,getChildIndex(_popupLayer));
		}
		
		private function unLockGame(data:Object=null):void
		{
			trace("");
			trace("解锁");
			if(_lockMask && _lockMask.parent)
				_lockMask.parent.removeChild(_lockMask);
		}
		
		private function showLoading(data:Object=null):void
		{
			DataCache.instance.lodingBool = true;
			lockGame();
			stage.addChild(_simpleLoadingMc);
			_simpleLoadingMc.play(); 
		}
		
		private function removeLoading(data:Object=null):void
		{
			DataCache.instance.lodingBool = false;
			if(_simpleLoadingMc.parent)
				_simpleLoadingMc.parent.removeChild(_simpleLoadingMc);
			_simpleLoadingMc.stop();
			unLockGame();
		}
		
		//显示解谜loading
		private function showPuzzleLoading(data:Object=null):void
		{
			if(_puzzleLoadingMc ==null)
			{
				_puzzleLoadingMc = UI.getUI("puzzleLoading","commonUI") as MovieClip;
				_puzzleLoadingMc.mouseChildren = false;
				_puzzleLoadingMc.mouseEnabled = false;
				SoundManager.playSound(SoundNameMap.enterCard);
//				_puzzleLoadingMc.height = 550;
//				_puzzleLoadingMc.scaleX = _puzzleLoadingMc.scaleY;
				
			}
			
			_puzzleLoadingMc.x = (stage.stageWidth - _puzzleLoadingMc.width)*0.5;
			_puzzleLoadingMc.y = (stage.stageHeight- _puzzleLoadingMc.height)*0.5;//110表示下面工具栏的高
			_puzzleLoadingMc.gotoAndPlay(1);
			//_effectLayer.addChild(_puzzleLoadingMc);
			//_houseLayer.addChild(_puzzleLoadingMc);
			stage.addChild(_puzzleLoadingMc);
		}
		
//		private function showPuzzleLoading(data:Object=null):void
//		{
//			if(_puzzleLoadingMc ==null)
//			{
//				_puzzleLoadingMc = UI.getPuzzleUI("CardLoadingMc") as MovieClip;
//				_puzzleLoadingMc.mouseChildren = false;
//				_puzzleLoadingMc.mouseEnabled = false;
//				_puzzleLoadingMc.gotoAndStop(1);
//				_puzzleLoadingMc.height = 550;
//				_puzzleLoadingMc.scaleX = _puzzleLoadingMc.scaleY;
//				
//			}
//			_puzzleLoadingMc.x = (stage.stageWidth - _puzzleLoadingMc.width)*0.5;
//			_puzzleLoadingMc.y = (stage.stageHeight - 102 - _puzzleLoadingMc.height)*0.5;//110表示下面工具栏的高
//			_houseLayer.addChild(_puzzleLoadingMc);
//		}
		
		
		//隐藏解谜loading
		private function hiddenPuzzleLoading(data:Object=null):void
		{
			if(_puzzleLoadingMc && _puzzleLoadingMc.parent)
			{
				_puzzleLoadingMc.gotoAndPlay("enterPuzzle");
//				NoticeCC.dispatch(ConstCC.PUZZLE_LOADING_END,null);
				_puzzleLoadingMc.addFrameScript(_puzzleLoadingMc.totalFrames-28,function():void{
					NoticeCC.dispatch(ConstCC.PUZZLE_LOADING_END,null);
				})
				_puzzleLoadingMc.addFrameScript(_puzzleLoadingMc.totalFrames-1,function():void{
					_puzzleLoadingMc.parent.removeChild(_puzzleLoadingMc);
					_puzzleLoadingMc.gotoAndStop(1);
					SoundManager.stopSound(SoundNameMap.enterCard);
				})
			}
				
			unLockGame();
		}
		
		//数据库连接错误
		private function onDataBaseDown(data:Object=null):void
		{
			//popRefreshPanel("数据库连接错误");
		}
		
		//服务器session过期
		private function onSessionExpire(data:Object=null):void
		{
			NoticeCS.request(ConstCS.SESSION_TIME_OUT, {sessionId:Proxy.sessionId});
			ASDebugger.debug("session过期");
			//popRefreshPanel("sessionExpire,action:"+data+" server:"+Proxy.serverURL);
		}
		
		//服务器关闭
		private function onServerClose(data:Object=null):void
		{
			popRefreshPanel("serverIOError,action:"+data+" server:"+Proxy.serverURL);
		}
		
		//服务器错误
		private function onServerError(data:Object=null):void
		{
			//popRefreshPanel("serverError,action:"+data+" server:"+Proxy.serverURL);
			this.showTweenMsg("连接失败："+ "serverError,action:"+data);
		}
		
		private function popRefreshPanel(errerCode:String=""):void
		{//梦被惊醒了，请刷新页面
			lockGame();
			if(_serverErrorPanel == null)
			{
				_serverErrorPanel = UI.getUI("ServerErrorPanel") as MovieClip;
			}
			_serverErrorPanel.errerCodeTxt.text = errerCode;
			if(_serverErrorPanel.parent == null)
			{
				_serverErrorPanel.x = int((stage.stageWidth - _serverErrorPanel.width)*0.5);
				_serverErrorPanel.y = int((stage.stageHeight - _serverErrorPanel.height)*0.5);
				_serverErrorPanel.refreshBtn.addEventListener(MouseEvent.MOUSE_DOWN,refresh);
				if(stage)
					stage.addChild(_serverErrorPanel);
				else
					this.addChild(_serverErrorPanel);
			}
			
		}
		
		
		//尺寸变化
		private function stageResize(evt:Event):void
		{
			this.x = int((stage.stageWidth - this.iniWidth)*0.5);
			this.y = int((stage.stageHeight - this.iniHeight)*0.5);
			
//			if(stage.displayState==StageDisplayState.FULL_SCREEN )//全屏
//			{
				//设置内容框
				if(Page.currentPage != Page.GARDEN)//不是在家园中
				{
					if(_contentFrame == null)
					{
						_contentFrame = new ContentFrame();
					}
					_contentFrame.x = int((stage.stageWidth-_contentFrame.width)*0.5);
					_contentFrame.y = int((stage.stageHeight-_contentFrame.height)*0.5);
					stage.addChildAt(_contentFrame, 1);
				}
//			}
//			else//正常
//			{
//				if(_contentFrame && _contentFrame.parent)
//				{
//					_contentFrame.parent.removeChild(_contentFrame);
//				}
//			}
			if(_lockMask)
			{
				_lockMask.graphics.clear();
				_lockMask.graphics.beginFill(0x0,0.3);
				_lockMask.graphics.drawRect(0,0,stage.stageWidth, stage.stageHeight);
				_lockMask.graphics.endFill();
				_lockMask.x=-(stage.stageWidth-ConstData.NormalWidth)/2;
				_lockMask.y=-(stage.stageHeight-ConstData.NormalHeight)/2;
			}
			
			_pendantLayer.x=int((stage.stageWidth-ConstData.NormalWidth)/2);
			_userInfoLayer.y=-int((stage.stageHeight-ConstData.NormalHeight)/2);
			TaskManager.getDefault().displayObj.x=-(stage.stageWidth-ConstData.NormalWidth);
			if(_dailyTastBtn)
				_dailyTastBtn.x = _dailyTastBtn.x = TaskManager.getDefault().displayObj.x+5;
//			_dailyTastBtn.y = TaskManager.getDefault().displayObj.y+320;
			_buttonLayer.y=515+(stage.stageHeight-ConstData.NormalHeight)/2;
		}
		
		//刷新游戏
		private function refresh(evt:MouseEvent=null):void
		{
			unLockGame();
			destroy();
			NoticeCC.dispatch(ConstCC.GAME_REFRESH);
			try{
				flash.external.ExternalInterface.call("freshGame");
			}catch(e:Error)
			{
				trace(e.message);
			}
			if(_serverErrorPanel.parent)
				_serverErrorPanel.parent.removeChild(_serverErrorPanel);
		}
		
		public function destroy():void
		{ 
			NoticeCC.removeListener(ConstCC.MSG_SHOW,showMsg);
			NoticeCC.removeListener(ConstCC.SHOW_TWEEN_MSG,showTweenMsg);
			//NoticeCC.removeListener(ConstCC.PAGE_TO_House,showHouse);
			NoticeCC.removeListener(ConstCC.PATE_TO_GARDEN,showGarden);
			NoticeCC.removeListener(ConstCC.PAGE_TO_CARD,showCard);
			NoticeCC.removeListener(ConstCC.PAGE_TO_COLLECTION,openCollectionPanel);
			NoticeCC.removeListener(ConstCC.PAGE_TO_FRIEND_COLLECTION,openFriendCollectionPanel);
			NoticeCC.removeListener(ConstCC.CARD_HIDDEN,hiddenCard);
			NoticeCC.removeListener(ConstCC.PAGE_TO_PUZZLE,showPuzzle);
			NoticeCC.removeListener(ConstCC.UNLOCK_GAME,unLockGame);
			NoticeCC.removeListener(ConstCC.LOCK_GAME,lockGame);
			NoticeSC.removeListener(NoticeSC.SERVER_CLOSE, onServerClose);
			NoticeSC.removeListener(NoticeSC.DATABASE_DOWN, onDataBaseDown);
			NoticeSC.removeListener(NoticeSC.SERVER_ERROR, onServerError);
			NoticeCC.removeListener(ConstCC.HIDDEN_GARDEN,hiddenHouse);
			NoticeCC.removeListener(ConstCC.SHOWDIYHOUSE_LOADING,showHouseLoading);
			NoticeCC.removeListener(ConstCC.HIDEHOUSE_LOADING,hiddenHouseLoading);
			//			NoticeCC.removeListener(ConstCC.UNLOCK_BOTTOMBAR,unlockBottomBar);
			//			NoticeCC.removeListener(ConstCC.LOCK_BOTTOMBAR,lockBottomBar);
			if(_serverErrorPanel)
				_serverErrorPanel.refreshBtn.removeEventListener(MouseEvent.MOUSE_DOWN,refresh);
		}
		
	}
}